package udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.Inet4Address;
import java.net.InetAddress;

/**
 * @author Mark
 * @version 1.0
 * @date 2020/5/17 18:01
 * @description UDP服务
 */
public class UdpClient {

    public static void main(String[] args) throws Exception {

        // 1.套接字
        DatagramSocket datagramSocket = new DatagramSocket();

        String msg = "你好，服务器";
        InetAddress localhost = Inet4Address.getByName("localhost");
        int port = 9090;
        DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, localhost, port);

        // 2.发包
        datagramSocket.send(packet);

        // 3.关闭流
        datagramSocket.close();
    }
}
